home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77705_shutdown_scheduleProp.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  40.7 KB  |  1,234 lines

  1. <%@ Language=VBScript %>
  2. <% Option Explicit      %>
  3. <% 
  4.     '-------------------------------------------------------------------------
  5.     ' shutdown_scheduleProp.asp :    Schedule shutdown/restart property page.
  6.     '
  7.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  8.     '
  9.     ' Date            Description
  10.     ' 02-01-2001    Created Date
  11.     ' 28-03-2001    Modified Date
  12.     '-------------------------------------------------------------------------
  13. %>
  14.     <!--#include virtual="/admin/inc_framework.asp"-->
  15.     <!-- #include file="loc_Shutdown_msg.asp" -->
  16.     <!-- #include file="inc_Shutdown.asp" -->
  17.     
  18. <%  
  19.     '--------------------------------------------------------------------------
  20.     'Global Variables
  21.     '--------------------------------------------------------------------------
  22.     Dim page                    'to hold the output page object when creating a page 
  23.     Dim rc                        'to hold the return value for CreatePage    
  24.     Dim G_strScheduledTask        'to hold the action whether restart or shutdown    
  25.     Dim G_strScheduledTaskLoc   'to hold the localization copy of shutdown/restart
  26.     Dim g_strWeekDay            'to hold the week day name
  27.     Dim g_DaysofWeek            'to hold day of the week
  28.     Dim g_intHours                'to hold Hours
  29.     Dim g_intMins                'to hold Mins
  30.     Dim g_intDays                'to hold Days
  31.     Dim g_strTask                'to hold the Task scheduled
  32.     Dim g_ScheduledShutdown        'to hold whether shutdown or restart is scheduled
  33.     
  34.     '-----------------------------------------------------------------------------
  35.     'Form Variables
  36.     '-----------------------------------------------------------------------------    
  37.     Dim F_strScheduleAction        'to hold Selected Schedule
  38.     Dim F_strScheduledOption    'to hold Schedduled date    
  39.     Dim F_strMinutes            'to hold Minutes for shutdown/restart
  40.     Dim    F_strHours                'to hold hour selected for shutdown/restart
  41.     Dim    F_strDays                'to hold days selected for shutdown/restart
  42.     Dim F_DayName                'to hold selected day name
  43.     Dim F_chkSendMessage        'to hold checkbox status of send message    
  44.     Dim    F_strScheduledTime        'to hold scheduled time
  45.     Dim    F_strSelectedWeekDay    'to hold selected week day    
  46.             
  47.     Const CONST_RESTART_APPLIANCE            = "Restart"
  48.     Const CONST_SHUTDOWN_APPLIANCE            = "Shutdown"
  49.     
  50.     Const CONST_ACTION_SCHEDULE_CANCEL        = 1
  51.     Const CONST_ACTION_SCHEDULE_SHUTDOWN    = 3
  52.     Const CONST_ACTION_SCHEDULE_RESTART        = 2
  53.  
  54.     Const CONST_SCHEDULE_DAYS_OPTION        = 1
  55.     Const CONST_SCHEDULE_WEEKDAYS_OPTION    = 2
  56.  
  57.     Const CONST_RAISERESTARTALERT            = 1
  58.     Const CONST_RAISESHUTDOWNALERT            = 1
  59.     
  60.     
  61.     'Create a Property Page
  62.     rc=SA_CreatePage(L_SCHEDULE_SHUTDOWN_TEXT,"",PT_PROPERTY,page)
  63.     
  64.     If (rc=0) Then
  65.         'Serve the page
  66.         SA_ShowPage(page)
  67.     End If
  68.     
  69.     '-------------------------------------------------------------------------
  70.     'Function:                OnInitPage()
  71.     'Description:            Called to signal first time processing for this page.
  72.     '                        Use this method to do first time initialization tasks
  73.     'Input Variables:        PageIn,EventArg
  74.     'Output Variables:        PageIn,EventArg
  75.     'Returns:                True/False
  76.     'Global Variables:        None
  77.     '-------------------------------------------------------------------------    
  78.     Public Function OnInitPage(ByRef PageIn,ByRef EventArg)     
  79.         Call SA_TraceOut("shutdown_scheduleprop", "OnInitPage")
  80.         
  81.         'Check whether Shutdown or restart is scheduled
  82.         if isScheduleShutdown then
  83.  
  84.             g_ScheduledShutdown = true
  85.             'get the date and time
  86.             Call GetDateAndTime()
  87.         
  88.         end if
  89.     
  90.         OnInitPage=true
  91.     End Function
  92.     
  93.     '-------------------------------------------------------------------------
  94.     'Function:                OnServePropertyPage()
  95.     'Description:            Called when the page needs to be served.Use this 
  96.     '                        method to serve content
  97.     'Input Variables:        PageIn,EventArg
  98.     'Output Variables:        PageIn,EventArg
  99.     'Returns:                True/False
  100.     'Global Variables:        None
  101.     '-------------------------------------------------------------------------    
  102.     Public Function OnServePropertyPage(ByRef PageIn,ByRef EventArg)
  103.         
  104.         Call SA_TraceOut("shutdown_scheduleprop", "OnServePropertyPage")
  105.  
  106.         If ( FALSE = IsSchedulerRunning() ) Then
  107.             Call SA_ServeFailurePage(L_ERROR_SCHEDULER_SERVICE_NOT_RUNNING)
  108.             Response.End
  109.             OnServePropertyPage = FALSE
  110.             Exit Function
  111.         End If
  112.  
  113.         'Serve client side script
  114.         Call ServeCommonJavaScript()
  115.         
  116.         'Serve the HTML content
  117.         Call ServeUI()
  118.         
  119.         OnServePropertyPage=TRUE
  120.     End Function
  121.  
  122.     '-------------------------------------------------------------------------
  123.     'Function:                OnPostBackPage()
  124.     'Description:            Called to signal that the page has been posted-back.
  125.     'Input Variables:        PageIn,EventArg
  126.     'Output Variables:        PageIn,EventArg
  127.     'Returns:                True/False
  128.     'Global Variables:        None
  129.     '-------------------------------------------------------------------------
  130.     Public Function OnPostBackPage(ByRef PageIn,ByRef EventArg)
  131.         Call SA_TraceOut("shutdown_scheduleprop", "OnPostBackPage")
  132.         
  133.         F_strScheduleAction = trim(request("rdoschedule"))
  134.         
  135.         F_strScheduledOption = trim(request("rdoScheduleDate"))
  136.         
  137.         F_strMinutes = request("optMinutes")
  138.         F_strHours = request("optHours")
  139.         F_strDays = request("optDays")
  140.         
  141.         F_DayName = Request.Form("DayName")
  142.         F_chkSendMessage = Request("chkSendMessage")
  143.         F_strScheduledTime = Request("txtAtTime")
  144.         F_strSelectedWeekDay = Request.Form("selWeekDay")
  145.         
  146.         OnPostBackPage=TRUE
  147.     End Function
  148.     
  149.     '-------------------------------------------------------------------------
  150.     'Function:                OnSubmitPage()
  151.     'Description:            Called when the page has been submitted for processing.
  152.     '                        Use this method to process the submit request.
  153.     'Input Variables:        PageIn,EventArg
  154.     'Output Variables:        PageIn,EventArg
  155.     'Returns:                True/False
  156.     'Global Variables/Constants:CONST_*
  157.     '-------------------------------------------------------------------------
  158.     Public Function OnSubmitPage(ByRef PageIn,ByRef EventArg)                
  159.         
  160.         Err.Clear
  161.         on error resume next
  162.         
  163.         Dim scheduledDayTime        'holds scheduled day and time    
  164.         Dim strHour                    'holds scheduled time
  165.         Dim scheduledOption            'holds scheduled option selected
  166.         Dim scheduledMinute            'holds scheduled minute
  167.         Dim scheduledHour            'holds scheduled hour    
  168.         Dim scheduledDay            'holds scheduled day
  169.         Dim objFso                    'holds filesystemobject
  170.         Dim Windirectory            'holds path of windows directory    
  171.         Dim strPathDay                    'holds shutdown executable file path
  172.         Dim strPathWeekday
  173.         Dim retVal                    'holds returnValue    
  174.         Dim strCommand                'to hold the command to run
  175.         Dim arrReplacementString    'to hold replacement string as an array to be passed as argument to raisealert
  176.         Dim ScheduleAction          'can be one of Cancel scheduled one, restart or shutdown
  177.         
  178.         Redim arrReplacementString(2) 'dimensioned to hold date and time strings
  179.                 
  180.  
  181.         ScheduleAction = F_strScheduleAction
  182.         
  183.         if ScheduleAction = trim(CONST_ACTION_SCHEDULE_CANCEL) then
  184.             'user wants to delete all the scheduled shutdown or restarts
  185.             'Check whether to remove the pending shutdown /restart        
  186.             Call SA_TraceOut("shutdown_scheduleprop", "User cancelled the schedule for the shutdown")
  187.             if isScheduleShutdown then
  188.                 DeleteSchedule()
  189.             end if
  190.             OnSubmitPage = True
  191.             Exit Function
  192.         end if
  193.  
  194.     
  195.         'Get Filesystem object
  196.         set objFso = CreateObject("Scripting.FileSystemObject")
  197.         Windirectory = objFso.GetSpecialFolder(1)
  198.         
  199.         'Release the object
  200.         set objFso = nothing
  201.  
  202.         ' Use different case to distinguish whether a scheduled job is weekday based or day based
  203.         ' For example, if the win32_scheduledJob object.Command contains "TASKSHUTDOWN.EXE", it's day
  204.         ' based. The solution is because of the difficulty to At.exe to generate weekday based 
  205.         ' win32_scheduledJob in localizied environment. Type At.exe/? in cmd line for details.
  206.         strPathDay = Windirectory & "\ServerAppliance\Web\admin\shutdown\support\TASKSHUTDOWN.EXE "
  207.         strPathWeekday = Windirectory & "\ServerAppliance\Web\admin\shutdown\support\taskshutdown.exe "
  208.         
  209.         'Check whether to Schedule a Restart
  210.         if ScheduleAction = trim(CONST_ACTION_SCHEDULE_RESTART) then
  211.             Call SA_TraceOut("shutdown_scheduleprop", "User  schedule for the restart")
  212.             G_strScheduledTask=CONST_RESTART_APPLIANCE
  213.             
  214.             ' Assign the loc msg to G_strScheduledTaskLoc. We cannot directly assign the loc msg
  215.             ' to G_strScheduledTask because it is used as a input for taskshutdown.exe, and 
  216.             ' taskshutdown.exe does not take shutdown|restart in English.
  217.             G_strScheduledTaskLoc = L_RESTART_TEXT
  218.             
  219.             if isScheduleShutdown then
  220.                 DeleteSchedule()
  221.             end if
  222.             
  223.         End if                                         
  224.         
  225.         'Check whether to Schedule a Shutdown
  226.         if ScheduleAction = trim(CONST_ACTION_SCHEDULE_SHUTDOWN) then
  227.             Call SA_TraceOut("shutdown_scheduleprop", "User  schedule for the shutdown")
  228.             G_strScheduledTask=CONST_SHUTDOWN_APPLIANCE
  229.             
  230.             ' Assign the loc msg to G_strScheduledTaskLoc
  231.             G_strScheduledTaskLoc = L_SHUTDOWN_TEXT
  232.             
  233.             if isScheduleShutdown then
  234.                 DeleteSchedule()
  235.             end if
  236.         End if
  237.         
  238.         'Get Date
  239.         scheduledOption= F_strScheduledOption        
  240.                         
  241.         'Get Day,Hour,Minute
  242.         If scheduledOption= trim(CONST_SCHEDULE_DAYS_OPTION) then            
  243.             scheduledMinute=Dateadd("N",F_strMinutes,now())
  244.             scheduledHour=Dateadd("H",F_strHours, scheduledMinute)
  245.             scheduledDay=Dateadd("D",F_strDays, scheduledHour)            
  246.             scheduledDayTime=Day(scheduledDay)
  247.             strHour= Hour(scheduledDay)&":"&Minute(scheduledDay)&":"&Second(scheduledDay) 
  248.         End if     
  249.         
  250.         
  251.         'Form the message to schedule the task using AT command
  252.         If scheduledOption=trim(CONST_SCHEDULE_DAYS_OPTION) then
  253.             Call SA_TraceOut("shutdown_scheduleprop", "User  schedule for the days option")
  254.             arrReplacementString = split(cstr(scheduledDay)," ")
  255.             if trim(arrReplacementString(2)) <> "" then
  256.                 arrReplacementString(1) = arrReplacementString(1) & " " & arrReplacementString(2)
  257.             end if
  258.             strCommand = "cmd.exe /c AT.exe "& replace(FormatDateTime(strHour,vbShortTime)," ","") &" /next:"& int(scheduledDayTime)& " " & strPathDay & "  " & G_strScheduledTask
  259.             
  260.         Elseif trim(scheduledOption)=trim(CONST_SCHEDULE_WEEKDAYS_OPTION) then
  261.             Call SA_TraceOut("shutdown_scheduleprop", "User  schedule for the weedays option")
  262.             arrReplacementString(0) = cstr(F_strSelectedWeekDay)
  263.             arrReplacementString(1) =  cstr(FormatDateTime(F_strScheduledTime,vbLongTime))
  264.             If Err.number <> 0 then
  265.                 SA_SetErrMsg L_INVALID_DATE_FORMAT
  266.                 Exit Function
  267.             End if
  268.             
  269.             ' Get the day for the selected weekday            
  270.             scheduledDayTime = CINT(GetDayForWeekday(F_strSelectedWeekDay))
  271.             
  272.             strCommand ="cmd.exe /c AT.exe "& replace(FormatDateTime(F_strScheduledTime,vbShortTime)," ","") &" /next:"& int(scheduledDayTime) & " " & strPathWeekday & "  " & G_strScheduledTask
  273.             'strCommand ="cmd.exe /c AT.exe "& replace(FormatDateTime(F_strScheduledTime,vbShortTime)," ","") &" /next:"& F_strSelectedWeekDay & " " & strPath & "  " & G_strScheduledTask
  274.         End if
  275.         
  276.         'Schedule selected task and raise alert
  277.         if TaskSchedule(trim(strCommand),arrReplacementString) = true  then
  278.             'Check whether SendMessage Check box is checked        
  279.             if F_chkSendMessage = "on" then
  280.                 If scheduledOption=trim(CONST_SCHEDULE_DAYS_OPTION) then
  281.                     call SendMessage(scheduledDay,G_strScheduledTask)
  282.                 Elseif scheduledOption=trim(CONST_SCHEDULE_WEEKDAYS_OPTION) then
  283.                     call SendMessage(Dateadd("d",F_DayName,Date) & " " &  FormatDateTime(F_strScheduledTime,vbLongTime),G_strScheduledTask)
  284.                 end if
  285.             end if
  286.             
  287.             OnSubmitPage= true
  288.         else
  289.             OnSubmitPage= false
  290.         end if
  291.         
  292.     End Function
  293.         
  294.     '----------------------------------------------------------------------------------
  295.     'Function:                OnClosePage()
  296.     'Description:            Called when the page is about to be closed.Use this method
  297.     '                        to perform clean-up processing
  298.     'Input Variables:        PageIn,EventArg
  299.     'Output Variables:        PageIn,EventArg
  300.     'Returns:                True/False
  301.     'Global Variables:        None
  302.     '----------------------------------------------------------------------------------    
  303.     Public Function OnClosePage(ByRef PageIn,ByRef EventArg)
  304.         OnClosePage=TRUE
  305.     End Function
  306.  
  307.     '-------------------------------------------------------------------------
  308.     'Function:                ServeCommonJavaScript
  309.     'Description:            Serves in initializing the values,setting the form
  310.     '                        data and validating the form values
  311.     'Input Variables:        None
  312.     'Output Variables:        None
  313.     'Returns:                True/False
  314.     'Global Variables:        None
  315.     '-------------------------------------------------------------------------
  316.     
  317.     Function ServeCommonJavaScript()
  318. %>
  319.         <script language="JavaScript" src="<%=m_VirtualRoot%>inc_global.js">
  320.         </script>
  321.         <script language="JavaScript">
  322.             
  323.             //
  324.             // Microsoft Server Appliance Web Framework Support Functions
  325.             // Copyright (c) Microsoft Corporation.  All rights reserved.
  326.             //
  327.             // Init Function
  328.             // -----------
  329.             // This function is called by the Web Framework to allow the page
  330.             // to perform first time initialization. 
  331.             //
  332.             // This function must be included or a javascript runtime error will occur.
  333.             //
  334.                     
  335.             function Init()
  336.             {            
  337.                 // This code take care of retaining of state, if any error 
  338.                 // reported in the execution of page
  339.                 var strScheduledTask = "<%= g_ScheduledShutdown %>";
  340.  
  341.                 var strRdoschedule = '<%= SA_EscapeQuotes(F_strScheduleAction) %>';    
  342.                 if (strRdoschedule != "" && strScheduledTask == "")
  343.                 {
  344.                     var optScheduledDate = '<%= SA_EscapeQuotes(F_strScheduledOption) %>';
  345.                     
  346.                     document.frmTask.rdoschedule[strRdoschedule - 1].checked = true;
  347.                     document.frmTask.rdoScheduleDate[optScheduledDate -    1].checked = true;            
  348.                     
  349.                     // Check which date option is selected
  350.                     
  351.                     // if selected first date option
  352.                     if (optScheduledDate == 1)
  353.                     {                    
  354.                         var strDays  = '<%=SA_EscapeQuotes(g_intDays)%>';
  355.                         document.frmTask.optDays.selectedIndex=strDays;
  356.                         
  357.                         var strHours = '<%=SA_EscapeQuotes(g_intHours)%>';
  358.                         document.frmTask.optHours.selectedIndex=strHours;
  359.                         
  360.                         var strMins = '<%=SA_EscapeQuotes(g_intMins)%>';                            
  361.                         document.frmTask.optMinutes.selectedIndex=strMins -1;
  362.                     
  363.                     }
  364.  
  365.                     // if selected second date option                    
  366.                     if (optScheduledDate == 2)
  367.                     {                    
  368.                         document.frmTask.txtAtTime.value = '<%=SA_EscapeQuotes(F_strScheduledTime)%>';
  369.                         var strSelectedDay = '<%=SA_EscapeQuotes(F_strSelectedWeekDay)%>';
  370.                         var intDay = 0;
  371.                         switch (strSelectedDay) 
  372.                         { 
  373.                             case '<%=SA_EscapeQuotes(L_MONDAYMSG_TEXT)%>':
  374.                                 intDay = 0;
  375.                                 break; 
  376.                             case '<%=SA_EscapeQuotes(L_TUESDAYMSG_TEXT)%>':
  377.                                 intDay = 1;
  378.                                 break; 
  379.                             case '<%=SA_EscapeQuotes(L_WEDNESDAYMSG_TEXT)%>':
  380.                                 intDay = 2;
  381.                                 break; 
  382.                             case '<%=SA_EscapeQuotes(L_THUSDAYMSG_TEXT)%>':
  383.                                 intDay = 3;
  384.                                 break; 
  385.                             case '<%=SA_EscapeQuotes(L_FRIDAYMSG_TEXT)%>':
  386.                                 intDay = 4;
  387.                                 break; 
  388.                             case '<%=SA_EscapeQuotes(L_SATURDAYMSG_TEXT)%>':
  389.                                 intDay = 5;
  390.                                 break; 
  391.                             case '<%=SA_EscapeQuotes(L_SUNDAYMSG_TEXT)%>':
  392.                                 intDay = 6;
  393.                                 break;
  394.                             default:
  395.                                 intDay = 0;    
  396.                                 
  397.                         }                    
  398.                         document.frmTask.selWeekDay.selectedIndex = intDay;
  399.                     }
  400.                     
  401.                     // Check for send message option
  402.                     var strSendMessage = '<%=SA_EscapeQuotes(F_chkSendMessage)%>';
  403.                     if (strSendMessage == "on")
  404.                     {
  405.                         document.frmTask.chkSendMessage.checked=true;
  406.                     }
  407.                     else
  408.                     {
  409.                         document.frmTask.chkSendMessage.checked=false;
  410.                     }
  411.                     return true; //exit function
  412.                     
  413.                 } // End of init function
  414.                                 
  415.                 if (strScheduledTask == "True")
  416.                 {     
  417.                     var WeekDay = '<%=SA_EscapeQuotes(g_strWeekDay) %>'; 
  418.                     document.frmTask.selWeekDay.selectedIndex=WeekDay;
  419.                 
  420.                     var strScheduleOption = '<%= SA_EscapeQuotes(g_DaysofWeek) %>';
  421.                     var strTask = '<%=SA_EscapeQuotes(g_strTask) %>';                     
  422.                     
  423.                     if (strScheduleOption == "True") 
  424.                     {    
  425.                         var strTime = '<%=SA_EscapeQuotes(g_intHours)%>' + ':' + '<%=SA_EscapeQuotes(g_intMins)%>';
  426.                         document.frmTask.txtAtTime.value = strTime;
  427.                         document.frmTask.rdoScheduleDate[1].checked = true;
  428.                         DisableSecondOption();
  429.                     }
  430.                     else
  431.                     {
  432.                         var strDays  = '<%=SA_EscapeQuotes(g_intDays)%>';
  433.                         document.frmTask.optDays.selectedIndex=strDays;                        
  434.                         
  435.                         
  436.                         var strHours = '<%=SA_EscapeQuotes(g_intHours)%>';
  437.  
  438.                         document.frmTask.optHours.selectedIndex=strHours;
  439.                         
  440.                         var strMins = '<%=SA_EscapeQuotes(g_intMins)%>';
  441.                         
  442.                         //strMins is set to 1 intentionally as the value in strMins is zero                        
  443.                         if (strMins == 0) 
  444.                             strMins = 1;
  445.                             
  446.                         document.frmTask.optMinutes.selectedIndex=strMins -1;
  447.                         
  448.                         MakeDisable();
  449.                     }
  450.  
  451.                     if (strTask == "Shutdown")
  452.                     {
  453.                         document.frmTask.rdoschedule[2].checked=true;
  454.                     }
  455.                     else if(strTask == "Restart")
  456.                     {
  457.                         document.frmTask.rdoschedule[1].checked=true;
  458.                     }
  459.                     else
  460.                     {
  461.                         document.frmTask.rdoschedule[0].checked=true;
  462.                     }
  463.                 }
  464.                 else
  465.                 {    
  466.                     //function call to disable other controls                    
  467.                     document.frmTask.optDays.disabled=true;
  468.                     document.frmTask.optHours.disabled=true;
  469.                     document.frmTask.optMinutes.disabled=true;                    
  470.                     document.frmTask.rdoScheduleDate[0].checked=false;
  471.                     document.frmTask.rdoScheduleDate[1].checked=false;                    
  472.                     document.frmTask.rdoScheduleDate[0].disabled=true;
  473.                     document.frmTask.rdoScheduleDate[1].disabled=true;
  474.                     
  475.                     MakeDisable();
  476.                                         
  477.                     document.frmTask.chkSendMessage.disabled=true;
  478.                 }    
  479.                 
  480.             }
  481.             
  482.             
  483.             function RemoveDisable()
  484.             {
  485.                 document.frmTask.selWeekDay.disabled=false;
  486.                 document.frmTask.txtAtTime.disabled=false;
  487.             }
  488.             function MakeDisable()
  489.             {
  490.                 document.frmTask.selWeekDay.disabled=true;
  491.                 document.frmTask.txtAtTime.disabled=true;
  492.             }        
  493.             
  494.             
  495.             function DisableFirstOption()
  496.             {
  497.                 document.frmTask.optDays.disabled=false;
  498.                 document.frmTask.optHours.disabled=false;
  499.                 document.frmTask.optMinutes.disabled=false;
  500.             }
  501.  
  502.             function DisableSecondOption()
  503.             {
  504.                 document.frmTask.optDays.disabled=true;
  505.                 document.frmTask.optHours.disabled=true;
  506.                 document.frmTask.optMinutes.disabled=true;
  507.             }
  508.             
  509.             // ValidatePage Function
  510.             // ------------------
  511.             // This function is called by the Web Framework as part of the
  512.             // submit processing. Use this function to validate user input. Returning
  513.             // false will cause the submit to abort. 
  514.             //
  515.             // This function must be included or a javascript runtime error will occur.
  516.             //
  517.             // Returns: True if the page is OK, false if error(s) exist.             
  518.             
  519.             function ValidatePage()
  520.             {                    
  521.                 document.frmTask.DayName.value = (document.frmTask.selWeekDay.selectedIndex) - 1;
  522.                 document.frmTask.hdnrdoschedule.value = document.frmTask.rdoschedule.checked;
  523.                 
  524.                 if (document.frmTask.rdoScheduleDate[0].checked == true) 
  525.                 {
  526.                     document.frmTask.hdnrdoScheduleDate.value = document.frmTask.rdoScheduleDate[0].value;
  527.                 }    
  528.                 else if (document.frmTask.rdoScheduleDate[1].checked == true)
  529.                 {
  530.                     //check whether time at scheduled day is entered
  531.                     if(document.frmTask.txtAtTime.value == "")
  532.                     {
  533.                         DisplayErr('<%= SA_EscapeQuotes(L_INVALID_DATE_FORMAT)%>');
  534.                         document.frmTask.onkeypress = ClearErr;
  535.                         return false;
  536.                     }                        
  537.                     document.frmTask.hdnrdoScheduleDate.value = document.frmTask.rdoScheduleDate[1].value;
  538.                 }                
  539.                 
  540.                 document.frmTask.hdnoptMinutes.value = document.frmTask.optMinutes.selectedIndex;
  541.                 document.frmTask.hdnoptHours.value = document.frmTask.optHours.selectedIndex;
  542.                 document.frmTask.hdnoptDays.value = document.frmTask.optDays.selectedIndex;                
  543.                 document.frmTask.hdnchkSendMessage.value = document.frmTask.chkSendMessage.checked
  544.                 document.frmTask.hdntxtAtTime.value = document.frmTask.txtAtTime.value;
  545.                 document.frmTask.hdnselWeekDay.value = document.frmTask.selWeekDay.selectedIndex;
  546.                 
  547.                 return true;
  548.             }
  549.             
  550.             // SetData Function
  551.             // --------------
  552.             // This function is called by the Web Framework and is called
  553.             // only if ValidatePage returned a success (true) code. Typically you would
  554.             // modify hidden form fields at this point. 
  555.             //
  556.             // This function must be included or a javascript runtime error will occur.
  557.             //
  558.             
  559.             function SetData()
  560.             {
  561.                 return true;
  562.             }
  563.             
  564.             //Function to disable other controlls when default option is selected 
  565.             function enableControls()
  566.             {    
  567.                 var ScheduleDate = document.frmTask.rdoScheduleDate;
  568.                 
  569.                 if(ScheduleDate[0].checked == false && ScheduleDate[1].checked == false || ScheduleDate[0].checked == true)
  570.                 {                    
  571.                     document.frmTask.optDays.disabled=false;
  572.                     document.frmTask.optHours.disabled=false;
  573.                     document.frmTask.optMinutes.disabled=false;                
  574.                     document.frmTask.chkSendMessage.disabled=false;
  575.                     ScheduleDate[0].checked = true;
  576.                     ScheduleDate[0].disabled = false;
  577.                     ScheduleDate[1].disabled = false;                    
  578.                     return true;
  579.                 }
  580.                         
  581.                 if(ScheduleDate[1].checked == true)
  582.                 {                    
  583.                     document.frmTask.optDays.disabled=true;
  584.                     document.frmTask.optHours.disabled=true;
  585.                     document.frmTask.optMinutes.disabled=true;                
  586.                     document.frmTask.chkSendMessage.disabled=false;
  587.                     document.frmTask.selWeekDay.disabled=false;
  588.                     document.frmTask.txtAtTime.disabled=false;
  589.                     ScheduleDate[1].checked = true;
  590.                     ScheduleDate[1].disabled = false;
  591.                     return true;
  592.                 }
  593.                     
  594.             }
  595.             
  596.             function DisableControls()
  597.             {
  598.                 document.frmTask.selWeekDay.disabled=true;
  599.                 document.frmTask.txtAtTime.disabled=true;                    
  600.                 document.frmTask.rdoScheduleDate[1].checked=false;
  601.                 //document.frmTask.rdoScheduleDate[1].checked=false;
  602.                 document.frmTask.optDays.disabled=true;
  603.                 document.frmTask.optHours.disabled=true;
  604.                 document.frmTask.optMinutes.disabled=true;
  605.                 document.frmTask.rdoScheduleDate[0].checked=false;
  606.                 document.frmTask.rdoScheduleDate[0].disabled=true;
  607.                 document.frmTask.rdoScheduleDate[1].disabled=true;
  608.                 document.frmTask.chkSendMessage.disabled=true;
  609.             }
  610.             
  611.         </script>
  612. <%    
  613.     End Function
  614.     
  615.     '----------------------------------------------------------------------------------
  616.     'Function:                ServeUI()
  617.     'Description:            Called to serve UI     
  618.     'Input Variables:        L_*;
  619.     'Output Variables:        None
  620.     'Functions Used:        GetListboxvalue()        
  621.     'Returns:                True/False
  622.     'Global Variables:        L_*, F_*
  623.     '----------------------------------------------------------------------------------
  624.     
  625.     Function ServeUI()
  626.         Call SA_TraceOut("shutdown_scheduleprop",  "ServeUI")
  627.             
  628.         
  629.         
  630.     %>
  631.         <TABLE WIDTH=518 VALIGN=CENTER ALIGN=left BORDER=0 CELLSPACING=0  CELLPADDING=2>
  632.  
  633.             <tr>
  634.                 <td class="TasksBody" NOWRAP>
  635.                      <INPUT type="radio" id=rad name=rdoschedule value=1 checked onclick="DisableControls();"> <%=L_NOSCHEDULE_TEXT%>
  636.                 </td>
  637.             </tr>
  638.  
  639.             <tr>
  640.                 <td class="TasksBody" width=25% NOWRAP>
  641.                      <INPUT type="radio" id=rad name=rdoschedule value=2 onclick="enableControls();"> <%=L_RESTARTSCHEDULED_TEXT%>
  642.                 </td>
  643.             </tr>
  644.             <tr>
  645.                 <td class="TasksBody" width=25% NOWRAP>
  646.                     <INPUT type="radio" id=rad name=rdoschedule value=3 onclick="enableControls();"> <%=L_SHUTDOWNSCHEDULED_TEXT%>
  647.                 </td>
  648.             </tr>
  649.             <tr>
  650.                 <td class="TasksBody" width=25% NOWRAP>
  651.                     <hr>
  652.                 </td>
  653.             </tr>
  654.             <tr>
  655.                  <td class="TasksBody" width=25% >
  656.                     <INPUT type="radio" name="rdoScheduleDate" value=1 checked OnClick="MakeDisable();DisableFirstOption()"> 
  657.                     <SELECT  name=optDays >
  658.                          <%=GetListboxvalue(0,27,"days")%>    
  659.                      </SELECT> <%=L_DAYS_TEXT%> 
  660.                      <SELECT  name=optHours>
  661.                          <%=GetListboxvalue(0,24,"Hrs")%>
  662.                     </SELECT> <%=L_HOURS_TEXT%> 
  663.                     <SELECT  name=optMinutes>
  664.                          <%=GetListboxvalue(1,60,"Min")%>
  665.                     </SELECT> <%=L_MINUTESFROMNOW_TEXT%>
  666.                 </td>                
  667.             </tr>
  668.             <tr>
  669.                 <td>
  670.                      
  671.                 </td>
  672.             </tr>
  673.             <tr>
  674.                 <td nowrap width=25% class="TasksBody">
  675.                     <%=L_OR_TEXT%>
  676.                 </td>                
  677.             </tr>
  678.             <tr>
  679.                 <td>
  680.                      
  681.                 </td>
  682.             </tr>
  683.             <tr>
  684.                 <td width=25% nowrap class="TasksBody">
  685.                     <INPUT type="radio"  name="rdoScheduleDate" value=2 OnClick="RemoveDisable();DisableSecondOption()"><%=L_ONTHENEXT_TEXT%> 
  686.                     <SELECT  name=selWeekDay>
  687.                     
  688.                        <OPTION value="<%=L_MONDAYMSG_TEXT%>"><%=L_MONDAYMSG_TEXT%></OPTION >
  689.                        
  690.                        <OPTION value="<%=L_TUESDAYMSG_TEXT%>"><%=L_TUESDAYMSG_TEXT%></OPTION >
  691.                        
  692.                        <OPTION value="<%=L_WEDNESDAYMSG_TEXT%>"><%=L_WEDNESDAYMSG_TEXT%> </OPTION >
  693.                        
  694.                        <OPTION value="<%=L_THUSDAYMSG_TEXT%>"><%=L_THUSDAYMSG_TEXT%>  </OPTION >
  695.                       
  696.                        <OPTION value="<%=L_FRIDAYMSG_TEXT%>"><%=L_FRIDAYMSG_TEXT%>  </OPTION >
  697.                       
  698.                        <OPTION value="<%=L_SATURDAYMSG_TEXT%>"><%=L_SATURDAYMSG_TEXT%></OPTION>
  699.                       
  700.                        <OPTION value="<%=L_SUNDAYMSG_TEXT%>"><%=L_SUNDAYMSG_TEXT%></OPTION >
  701.                        
  702.                     </SELECT> <%=L_AT_TEXT%> 
  703.                     <input type=text name=txtAtTime value="<%= F_strScheduledTime %>" maxlength=12 size=15>
  704.                 </td>                
  705.             </tr>
  706.             <tr>
  707.                 <td class="TasksBody">
  708.                      
  709.                 </td>
  710.             </tr>
  711.             <tr>
  712.                 <td class="TasksBody">
  713.                      
  714.                 </td>
  715.             </tr>
  716.             <tr>
  717.                 <td class="TasksBody">
  718.                     <input NAME="chkSendMessage" TYPE="Checkbox" > <%=L_NETSENDWARNING_TEXT%>
  719.                 </td>
  720.             </tr>
  721.         </TABLE>
  722.         <input type = hidden name = "DayName" value="F_DayName">
  723.         <input type = hidden name = "hdnrdoschedule" value="<%=F_strScheduleAction%>">
  724.         <input type = hidden name = "hdnrdoScheduleDate" value="<%=F_strScheduledOption%>">
  725.         <input type = hidden name = "hdnoptMinutes" value="<%=F_strMinutes%>">
  726.         <input type = hidden name = "hdnoptHours" value="<%=F_strHours%>">
  727.         <input type = hidden name = "hdnoptDays" value="<%=F_strDays%>">        
  728.         <input type = hidden name = "hdnchkSendMessage" value="<%=F_chkSendMessage%>">
  729.         <input type = hidden name = "hdntxtAtTime" value="<%=F_strScheduledTime%>">
  730.         <input type = hidden name = "hdnselWeekDay" value="<%=F_strSelectedWeekDay%>">
  731.     <%
  732.     End Function
  733.     
  734.     '-------------------------------------------------------------------------
  735.     'Function:                GetListboxvalue()
  736.     'Description:            Called to get list box value
  737.     'Input Variables:        Min,Max
  738.     'Output Variables:        None
  739.     'Returns:                True/False
  740.     'Global Variables:        None
  741.     '-------------------------------------------------------------------------        
  742.     
  743.     Function GetListboxvalue(Min,Max,Val)
  744.         Dim nMaxLoopValue    'hold max value
  745.         Dim nMinLoopValue    'hold min value
  746.  
  747.         Call SA_TraceOut("shutdown_scheduleprop",  "GetListboxvalue")
  748.         
  749.         For nMaxLoopValue = Min to Max 
  750.             If nMaxLoopValue <= 9 then
  751.                 nMinLoopValue = "0" & nMaxLoopValue
  752.             Else
  753.                 nMinLoopValue = nMaxLoopValue
  754.             End if 
  755.                 
  756.             If (Val = "Min") Then
  757.                 %>
  758.                     <OPTION value=<%=nMinLoopValue%> ><%=nMinLoopValue%></OPTION>
  759.                 <%         
  760.             Else
  761.                 %>
  762.                     <OPTION value=<%=nMinLoopValue%> ><%=nMaxLoopValue%></OPTION>
  763.                 <%     
  764.             End if    
  765.         Next
  766.     End function
  767.  
  768.    '-------------------------------------------------------------------------
  769.     'Function:                TaskSchedule()
  770.     'Description:            Function to schedule shutdown /restart
  771.     'Input Variables:        strCommand,ReplacementString
  772.     'Output Variables:        None
  773.     'Returns:                True/False
  774.     'Global Variables:        G_*, L_*
  775.     '-------------------------------------------------------------------------   
  776.        Function TaskSchedule(strCommand,ReplacementString)
  777.         Err.clear
  778.         On Error Resume Next
  779.                 
  780.         Dim strCurDir            'holds current directory    
  781.         Dim returnValue            'holds return value    
  782.         Dim objFso                'holds File System object
  783.         Dim Windirectory        'holds Window directory path
  784.         Dim Alertid                'holds the alert ID
  785.         Dim arrRepStrings            'holds the replacement strings
  786.         
  787.         redim arrRepStrings(1)
  788.  
  789.         ' Assign a loc msg for output error msg
  790.         arrRepStrings(0) = cstr(G_strScheduledTaskLoc)
  791.                                       
  792.         TaskSchedule=false
  793.         
  794.         Call SA_TraceOut("shutdown_scheduleprop",  "calling shutdownraise alert func " + G_strScheduledTask)
  795.  
  796.         set objFso = CreateObject("Scripting.FileSystemObject")        
  797.         Windirectory = objFso.GetSpecialFolder(0)        
  798.         strCurDir=left(Windirectory,3)
  799.         
  800.         'Release the object
  801.         set objFso = nothing
  802.  
  803.         returnValue = LaunchProcess(strCommand, strCurDir)        
  804.         If Err.number<> 0 then
  805.             TaskSchedule=False
  806.             L_UNABLETOLAUNCHPROCESS_ERRORMESSAGE = SA_GetLocString("sashutdown_msg.dll", "C040001F", arrRepStrings)
  807.             SA_SetErrMsg L_UNABLETOLAUNCHPROCESS_ERRORMESSAGE & "(" & Err.number & ")"
  808.             Exit function
  809.         End if
  810.  
  811.         Alertid = 1        
  812.         
  813.         if returnValue = 0 then
  814.             Call SA_TraceOut("shutdown_scheduleprop.asp",  "calling shutdownraise inside if ")            
  815.             
  816.             'Raise alert for the scheduled task 
  817.             if UCase(G_strScheduledTask) = ucase(CONST_RESTART_APPLIANCE) then
  818.                 Call SA_TraceOut("shutdown_scheduleprop.asp","inside if RestartPending")
  819.                 retval = ShutdownRaiseAlert(Alertid,"RestartPending",ReplacementString)
  820.         
  821.             elseif UCase(G_strScheduledTask) = ucase(CONST_SHUTDOWN_APPLIANCE) then
  822.                 Call SA_TraceOut("shutdown_scheduleprop.asp","inside if ShutdownPending")
  823.                 retval = ShutdownRaiseAlert(Alertid,"ShutdownPending",ReplacementString)
  824.         
  825.             end if    
  826.             Call SA_TraceOut("shutdown_scheduleprop.asp",UCase(G_strScheduledTask) + ucase(CONST_RESTART_APPLIANCE) )
  827.         end if 
  828.                 
  829.         TaskSchedule = true
  830.             
  831.     End Function
  832.     
  833.     
  834.     '-------------------------------------------------------------------------
  835.     'Function:                DeleteSchedule
  836.     'Description:            Serves in deleting the scheduled task
  837.     'Input Variables:        None
  838.     'Output Variables:        None
  839.     'Returns:                True/False
  840.     'Global Variables/Constants:L_(*)-Localization Strings, CONST_*
  841.     '-------------------------------------------------------------------------    
  842.     Function DeleteSchedule()
  843.         Err.Clear
  844.         On Error Resume Next
  845.         
  846.         Dim objWMIConnection     'To get WMI connection    
  847.         Dim objSchedule            'To get instance of wmi class
  848.         Dim strSchedule            'To hold scheduled task instance
  849.         Dim strVal                'To get the value of task run(shutdown or restart)
  850.         
  851.         Call SA_TraceOut("shutdown_scheduleprop",  "DeleteSchedule")
  852.         
  853.         'getting wmi connection
  854.         set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  855.         
  856.         'taking the instance of wmi class responsible for scheduling
  857.         set objSchedule=objWMIConnection.Instancesof("Win32_ScheduledJob")
  858.         
  859.         'deleting a scheduled task
  860.         for each strSchedule in objSchedule
  861.         
  862.             strVal = Ucase(right(strSchedule.Command,15))
  863.             'Check for restart entry
  864.             
  865.             if instr(1,strVal,Ucase(CONST_RESTART_APPLIANCE),1) > 0 then                        
  866.                 strSchedule.Delete()
  867.                 if Err.number <> 0 then                  
  868.                     SA_SetErrMsg L_UNABLETODELETE_SCHEDULEDTASK_ERRORMESSAGE
  869.                 Else
  870.                     'Clear the Restart alert message
  871.                     DeleteAlert(CONST_RAISERESTARTALERT) ' the arg is alert ID
  872.                 End if
  873.                 
  874.                 'Check for shutdown entry 
  875.             elseif instr(1,strVal,Ucase(CONST_SHUTDOWN_APPLIANCE),1) > 0 then
  876.                 strSchedule.Delete()    
  877.                 if Err.number <> 0 then 
  878.                     SA_SetErrMsg L_UNABLETODELETE_SCHEDULEDTASK_ERRORMESSAGE
  879.                 Else
  880.                     'Clear the Shutdown alert message            
  881.                     DeleteAlert(CONST_RAISESHUTDOWNALERT)' the arg is alert ID
  882.                 End if                
  883.             end if
  884.         
  885.         next    
  886.     
  887.         If Err.number<>0 then
  888.             SA_SetErrMsg L_UNABLETODELETE_SCHEDULEDTASK_ERRORMESSAGE
  889.             DeleteSchedule=False
  890.             Exit Function
  891.         End If
  892.         
  893.         DeleteSchedule=True            
  894.         
  895.         'destroying dynamically created objects
  896.         Set objWMIConnection=Nothing
  897.         Set objSchedule=Nothing    
  898.         
  899.     End Function
  900.     
  901.     
  902.     '-------------------------------------------------------------------------
  903.     'Function:                GetDateAndTime
  904.     'Description:            gets the date and time 
  905.     'Input Variables:        None
  906.     'Output Variables:        None
  907.     'Returns:                Date and Time
  908.     'Global Variables/Constants:L_*, CONST_*, g_*
  909.     '-------------------------------------------------------------------------
  910.     Function GetDateAndTime()
  911.     
  912.         Err.Clear
  913.         on error resume next
  914.     
  915.         Dim objWMIConnection     'To get WMI connection    
  916.         Dim objSchedule            'To get instance of wmi class
  917.         Dim strScheduleType        'To get type of scheduled task
  918.         Dim strSchedule            'To get scheduled task results
  919.         Dim strHours            'To hold time in hours
  920.         Dim strMins                'To hold time in mins        
  921.         
  922.         Const CONST_RESTARTAPPLIANCE = "Restart"
  923.         Const CONST_SHUTDOWNAPPLIANCE= "Shutdown"
  924.         Const CONST_HOURSPERDAY    = 24
  925.         
  926.         Call SA_TraceOut("shutdown_scheduleprop", "GetDateAndTime")
  927.         
  928.         'getting wmi connection
  929.         set objWMIConnection = getWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  930.         
  931.         'getting the instance of wmi class responsible for scheduling
  932.         set objSchedule=objWMIConnection.Instancesof("Win32_ScheduledJob")
  933.         
  934.         If Err.number <>0 Then
  935.             SA_SetErrMsg L_WMICLASSINSTANCEFAILED_ERRORMESSAGE
  936.             Exit Function
  937.         End If
  938.                 
  939.         for each strSchedule in objSchedule
  940.             
  941.             'getting the type of scheduled task
  942.             strScheduleType=Ucase(right(strSchedule.Command,8))
  943.  
  944.             'checking the scheduled task type
  945.             If instr(strScheduleType,Ucase(CONST_RESTARTAPPLIANCE))>0 then 
  946.                 g_strTask = CONST_RESTARTAPPLIANCE
  947.             elseIf instr(strScheduleType,Ucase(CONST_SHUTDOWNAPPLIANCE))>0 then 
  948.                 g_strTask = CONST_SHUTDOWNAPPLIANCE
  949.             end if
  950.             
  951.     
  952.             'check whether shutdown or restart is scheduled already
  953.             if g_strTask = CONST_RESTARTAPPLIANCE or g_strTask = CONST_SHUTDOWNAPPLIANCE then
  954.                 
  955.                 strHours =  mid(strSchedule.StartTime,9,2)                
  956.                                         
  957.                 strMins = mid(strSchedule.StartTime,11,2)
  958.                     
  959.  
  960.                 if inStr(1, trim(strSchedule.Command), "TASKSHUTDOWN.EXE", 0) then 'find whether Days of Month is not null                
  961.                 'if not isnull(trim(strSchedule.DaysOfMonth)) then 'find whether Days of Month is not null
  962.  
  963.                     g_DaysofWeek = false
  964.                     
  965.                     'get the date of schedule
  966.                     Call GetDate(strSchedule.DaysOfMonth,strHours,strMins)
  967.                 
  968.                     exit function
  969.                     
  970.                 elseif inStr( trim(strSchedule.Command), "taskshutdown") then
  971.  
  972.                     g_DaysofWeek = true
  973.                     
  974.                     g_intHours =  mid(strSchedule.StartTime,9,2)
  975.                                         
  976.                     g_intMins = mid(strSchedule.StartTime,11,2)
  977.                                     
  978.                     'get the date of schedule
  979.                     'Call GetDateforWeek(strSchedule.DaysOfWeek)
  980.                     
  981.                     Call GetWeekdayForDate(strSchedule.DaysOfMonth)
  982.                     
  983.                     exit function
  984.             
  985.                 end if
  986.             
  987.             end if
  988.             
  989.         Next
  990.         
  991.         'Release the objects
  992.         set objWMIConnection = nothing
  993.         set objSchedule = nothing
  994.  
  995.     End function
  996.     
  997.     '-------------------------------------------------------------------------
  998.     'Function:                GetDateforWeek
  999.     'Description:            gets the date in terms of day
  1000.     'Input Variables:        intWeek
  1001.     'Output Variables:        None
  1002.     'Returns:                Day of the week
  1003.     'Global Variables:        g_strWeekDay
  1004.     '-------------------------------------------------------------------------
  1005.     Function GetDateforWeek(intWeek)
  1006.         
  1007.         Dim count    'to hold count
  1008.         
  1009.         Call SA_TraceOut("shutdown_scheduleprop", "GetDateforWeek")
  1010.         
  1011.         for count = 0 to 6
  1012.             if 2 ^ count = intWeek then
  1013.                 g_strWeekDay = count
  1014.             end if
  1015.         next
  1016.         
  1017.     End Function        
  1018.  
  1019.     '-------------------------------------------------------------------------
  1020.     'Function:                GetDate
  1021.     'Description:            gets the date in terms of day
  1022.     'Input Variables:        intDays, intHours, intMins
  1023.     'Output Variables:        None
  1024.     'Returns:                Day of the week
  1025.     'Global Variables:        g_*
  1026.     '-------------------------------------------------------------------------
  1027.     Function GetDate(intDays,intHours,intMins)
  1028.  
  1029.         Dim count                    'hold the count
  1030.         Dim strdaysScheduledFor        'hold the days for the task scheduled
  1031.         Dim strCurrentDate            'hold the current date
  1032.         Dim strScheduledDate        'hold the scheduled date
  1033.         Dim strScheduledMonth        'hold the scheduled month
  1034.         Dim strScheduledYear        'hold the scheduled year
  1035.         Dim strHours                'hold the hours part
  1036.         Dim strMinute                'hold the minutes part
  1037.         
  1038.         CONST CONST_MINUTESPERDAY  = 1440
  1039.         CONST CONST_MAXDAYS = 27
  1040.         CONST CONST_MAXHOURS = 24
  1041.         CONST CONST_MINUTESPERHOUR = 60
  1042.         
  1043.         Call SA_TraceOut("shutdown_scheduleprop", "GetDate")
  1044.                 
  1045.         for count = 0 to 31
  1046.             if 2 ^ count = intDays then
  1047.                 strdaysScheduledFor = count + 1
  1048.             end if
  1049.         next        
  1050.         
  1051.         'get the current date
  1052.         strCurrentDate = Date()        
  1053.                 
  1054.         if strdaysScheduledFor < day(date()) then
  1055.             strScheduledMonth = Month(DateAdd("m",1,Date()))
  1056.             strScheduledYear = year(Date())
  1057.         else
  1058.             strScheduledMonth = Month(Date())
  1059.             strScheduledYear = year(Date())
  1060.         end if
  1061.         
  1062.         'format the scheduled date using the universal format
  1063.         strScheduledDate = strScheduledYear & "-" & strScheduledMonth & "-" & strdaysScheduledFor    
  1064.         
  1065.         Dim strDate
  1066.         strDate = strScheduledDate & " " & formatdatetime(intHours & ":" & intMins & ":00",vbLongTime)
  1067.         
  1068.         ' Format the date to the current localization setting
  1069.         strDate = formatdatetime(strDate, vbGeneralDate)
  1070.         
  1071.         'get the difference in minutes between current date and scheduled date
  1072.         strMinute  =  datediff("n",now, strDate)
  1073.  
  1074.         'if minutes are more than one day(1440 minutes)
  1075.         if strMinute > CONST_MINUTESPERDAY then
  1076.  
  1077.             g_intDays = int(strMinute/CONST_MINUTESPERDAY)
  1078.             
  1079.             strMinute = strMinute - (g_intDays * CONST_MINUTESPERDAY)
  1080.  
  1081.             g_intHours = int(strMinute/ CONST_MINUTESPERHOUR)
  1082.             
  1083.             g_intMins = strMinute mod CONST_MINUTESPERHOUR
  1084.             
  1085.         else
  1086.             g_intDays = 0
  1087.             g_intHours = cint(strMinute) / CONST_MINUTESPERHOUR
  1088.             g_intMins = strMinute mod CONST_MINUTESPERHOUR
  1089.  
  1090.         end if
  1091.             
  1092.         'Check for the max days(last element in the days dropdown box)
  1093.         if g_intDays > CONST_MAXDAYS  then 
  1094.             g_intdays = CONST_MAXDAYS
  1095.             g_intHours = CONST_MAXHOURS
  1096.             g_intMins = strMinute
  1097.         end if
  1098.                 
  1099.     End Function
  1100.     
  1101.     
  1102.     '-------------------------------------------------------------------------
  1103.     'Function:                GetDayForWeekday
  1104.     'Description:            Get the day for a weekday. For example, if next
  1105.     '                        Monday is 3/20/2002, it returns 20
  1106.     'Input Variables:        strWeekday
  1107.     'Output Variables:        None
  1108.     'Returns:                day
  1109.     'Global Variables:        None
  1110.     '-------------------------------------------------------------------------
  1111.     Function GetDayForWeekday( strWeekday )
  1112.  
  1113.         Dim iToday
  1114.         Dim dayInterval
  1115.         Dim strDate
  1116.         Dim iWeekday
  1117.         
  1118.         iWeekday = GetWeekday(strWeekday)
  1119.  
  1120.         ' Get today's date
  1121.          iToday = Weekday(date)
  1122.                 
  1123.         dayInterval = iWeekday - iToday
  1124.         If dayInterval < 1 Then
  1125.             dayInterval = dayInterval + 7
  1126.         End If
  1127.         
  1128.         ' Get the date for the input weekday
  1129.         strDate = DateAdd("D", dayInterval, date)
  1130.             
  1131.         GetDayForWeekday = Day(strDate)
  1132.         
  1133.     End Function
  1134.     
  1135.     '-------------------------------------------------------------------------
  1136.     'Function:                GetWeekDay
  1137.     'Description:            gets the weekday 
  1138.     'Input Variables:        strWeekday
  1139.     'Output Variables:        None
  1140.     'Returns:                weekday 
  1141.     'Global Variables:        None
  1142.     '-------------------------------------------------------------------------
  1143.     Function GetWeekday(strWeekday)
  1144.             
  1145.         if ( strWeekday = L_SUNDAYMSG_TEXT ) Then
  1146.             GetWeekday = vbSunday
  1147.     
  1148.         elseif ( strWeekday = L_MONDAYMSG_TEXT ) Then
  1149.             GetWeekday = vbMonday
  1150.             
  1151.         elseif ( strWeekday = L_TUESDAYMSG_TEXT ) Then
  1152.             GetWeekday = vbTuesday
  1153.         
  1154.         elseif ( strWeekday = L_WEDNESDAYMSG_TEXT ) Then
  1155.             GetWeekday = vbWednesday
  1156.             
  1157.         elseif ( strWeekday = L_THUSDAYMSG_TEXT ) Then
  1158.             GetWeekday = vbThursday
  1159.             
  1160.         elseif ( strWeekday = L_FRIDAYMSG_TEXT ) Then
  1161.             GetWeekday = vbFriday
  1162.             
  1163.         elseif ( strWeekday = L_SATURDAYMSG_TEXT ) Then
  1164.             GetWeekday = vbSaturday
  1165.         
  1166.         end if
  1167.                 
  1168.     End Function
  1169.     
  1170.     
  1171.     '-------------------------------------------------------------------------
  1172.     'Function:                GetWeekdayForDate
  1173.     'Description:            gets the date in terms of day
  1174.     'Input Variables:        intDay
  1175.     'Output Variables:        None
  1176.     'Returns:                Day of the week
  1177.     'Global Variables:        g_strWeekday
  1178.     '-------------------------------------------------------------------------
  1179.     Function GetWeekdayForDate(intDays)
  1180.  
  1181.         Dim count                    'hold the count
  1182.         Dim strdaysScheduledFor        'hold the days for the task scheduled
  1183.         Dim strScheduledMonth        'hold the scheduled month
  1184.         Dim strScheduledYear        'hold the scheduled year
  1185.         Dim strScheduledWeekday        'hold the scheduled weekday
  1186.                 
  1187.         for count = 0 to 31
  1188.             if 2 ^ count = intDays then
  1189.                 strdaysScheduledFor = count + 1
  1190.             end if
  1191.         next
  1192.             
  1193.         if strdaysScheduledFor < day(date()) then
  1194.             strScheduledMonth = Month(DateAdd("m",1,Date()))
  1195.             strScheduledYear = year(Date())
  1196.         else
  1197.             strScheduledMonth = Month(Date())
  1198.             strScheduledYear = year(Date())
  1199.         end if
  1200.         
  1201.         ' Get the weekday of the date
  1202.         g_strWeekDay = weekday( strScheduledYear & "-" & strScheduledMonth & "-" & strdaysScheduledFor)        
  1203.         
  1204.         ' Convert it to the index number to select from the weekday list
  1205.         g_strWeekday = CInt((g_strWeekday + 7 - 2) mod 7)
  1206.         
  1207.     End function
  1208.         
  1209.  
  1210. Public Function IsSchedulerRunning()
  1211.     Dim oWMI
  1212.     Dim oService 
  1213.  
  1214.     IsSchedulerRunning = FALSE
  1215.  
  1216.     Set oWMI = GetWMIConnection(CONST_WMI_WIN32_NAMESPACE)
  1217.  
  1218.     Set oService = oWMI.Get("Win32_Service.Name='Schedule'")
  1219.     If ( Err.Number <> 0 ) Then
  1220.         Exit Function
  1221.     End If
  1222.  
  1223.     If ( oService.State = "Running" ) Then    
  1224.         IsSchedulerRunning = TRUE
  1225.     End If
  1226.  
  1227.     Set oService = Nothing
  1228.     Set oWMI = Nothing
  1229.  
  1230. End Function
  1231.         
  1232.  
  1233. %>
  1234.